const express = require("express");
const app = express();
const url = require("url");
const vipLogin = require("./data/vip_login.json");
const adminLogin = require("./data/admin_login.json");

app.get("/login", (req, res) => {
  const user = url.parse(req.url, true).query.user;
  if (user === "admin") {
    res.send(adminLogin);
  } else {
    res.send(vipLogin);
  }
});

const adminPermissionTwo = require("./data/admin_permissionTwo.json");
const vipPermission = require("./data/vip_permission.json");
const adminPermissionThree = require("./data/admin_permissionThree.json");
app.get("/permission", (req, res) => {
  const user = url.parse(req.url, true).query.user;

  if (user === "admin2") {
    res.send(adminPermissionTwo);
  } else if (user === "admin3") {
    res.send(adminPermissionThree);
  } else {
    res.send(vipPermission);
  }
});

app.listen(3300, () => {
  console.log("server is running on port 3300");
});
